package com.laboratory.report.lab03;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.Vector;

/**
 * @author tangheng
 */
public class OlympicTable extends JPanel {

    private DefaultTableModel tableModel;
    private JTable table;
    private Vector<String> columnNames = new Vector<>();


    public OlympicTable() {
        setLayout(new BorderLayout(0, 0));

        columnNames.add("ID");
        columnNames.add("代表队");
        columnNames.add("金牌");
        columnNames.add("银牌");
        columnNames.add("铜牌");
        columnNames.add("合计");

        // 创建表格模型
        tableModel = new DefaultTableModel(columnNames, 10);
        // 创建JTable表格组件
        table = new JTable(tableModel);
        add(table.getTableHeader(), BorderLayout.NORTH);
        // 将带滚动条的面板添加到布局中（布局的中间）
        add(table, BorderLayout.CENTER);
    }

    public void showData(Vector<Vector<Object>> rowData) {
        tableModel.setDataVector(rowData, columnNames);
        table.updateUI();
    }
}
